<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创建dom元素</title>
    <style>
        img{
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>
    <button type="button" onclick="add()">添加一张图片</button>
    <button type="button" onclick="del()">删除一张图片</button>
    <div id="outer">
        <img src="../imgs/猫.jpg" alt="">
    </div>
    <script>
        let outer = document.querySelector("#outer")
        console.log(outer)

        function add(){
            //1. 创建一个dom元素-img
            let img = document.createElement("img");
            //通过对象.属性来设置属性值
            // img.src='../imgs/猫.jpg'
            img.src=outer.children[0].src

            //2. 将创建之后的img元素绑定到div中
            outer.append(img)
            // outer.appendChild(img)
        }

        function del(){
            //1. 获取最后一个元素
            let last = outer.lastElementChild
            //2. 删除
            //last.remove();//哪个元素调用remove()方法,哪个元素就会被删除
            outer.removeChild(last);//从div中删除last

        }
    </script>
</body>
</html>